<script type="text/javascript" language="javascript">
var oTable;
var giRedraw = false;
var select;
    
	var nCloneTh = document.createElement( 'th' );
	var nCloneTd = document.createElement( 'td' );
	nCloneTd.innerHTML = '<img src="resources/images/details_open.png" alt="+" />';
	nCloneTd.className = "center";
	
function vymaz (email) {
	select = email;
}
</script>
{if isset($data.sub['sub'])}
{if $data.sub['sub'] eq 'registration'}
<script type="text/javascript" language="javascript">
function fnFormatDetails ( oTable, nTr )
{
	var aData = oTable.fnGetData( nTr );
	var sOut ='<form action="home?action=addUser" method="post">';
	sOut +=	'<input type="hidden" name="email" value="'+aData[3]+'" />';
	sOut +=	'<input type="submit" class="button" value="Schváliť" />';
	sOut +=	'</form>';
	sOut +=	'<form action="home?action=deleteUser" method="post">';
	sOut +=	'<input type="hidden" name="email" value="'+aData[3]+'" />';
	sOut +=	'<input type="submit" class="button"  value="Zamietnuť" />';
	sOut +='</form>';
	return sOut;
}
</script>
{/if}


{if $data.sub['sub'] eq 'rights'}
<script type="text/javascript" language="javascript">
function fnFormatDetails ( oTable, nTr )
{
	
    	
	var aData = oTable.fnGetData( nTr );
	var sOut ='<form action="home?action=addRight" method="post">';
	sOut +=	'<input type="hidden" name="id" value="'+aData[1]+'" />';

    var w = aData[4][7];
    var a = aData[4][13];
    var e = aData[4][20];
    var d = aData[4][29];
    	
	sOut +=	'watch: <input type="checkbox" name="watch"';  
	if(w=='1') {
		sOut += ' checked="yes"';
	}
	sOut += ' />';
	

	sOut +=	'add:   <input type="checkbox" name="add"';   
	if(a=='1') {
		sOut += ' checked="yes"';
	}
	sOut += ' />';
	
	sOut +=	'edit:  <input type="checkbox" name="edit"';   
	if(e=='1') {
		sOut += ' checked="yes"';
	}
	sOut += ' />';
	
	sOut +=	'delete:<input type="checkbox" name="delete"';   
	if(d=='1') {
		sOut += ' checked="yes"';
	}
	sOut += ' />';
	
	sOut +=	'<input type="submit" class="button" value="Schváliť" />';
	sOut +=	'</form>';
	
	sOut +=	'<form action="home?action=deleteRight" method="post">';
	sOut +=	'<input type="hidden" name="id" value="'+aData[1]+'" />';
	sOut +=	'<input type="submit" class="button"  value="Zamietnuť" />';
	sOut +=	'</form>';
	return sOut;
}
</script>
{/if}

{/if}


<script type="text/javascript" language="javascript">
$(document).ready(function() {
	 $('.del').click( function() {
	 	select=aData[3];
	 	alert("jfaskl");
       	var anSelected = fnGetSelected( oTable );
       	var pole = new Array();
       	pole = fnGetSelected(oTable);
       	for(var i=0; i < pole.length; i++){
       		oTable.fnDeleteRow( anSelected[i] );
       	}

   } );
	$('#admin_table thead tr').each( function () {
		this.insertBefore( nCloneTh, this.childNodes[0] );
	} );
	
	$('#admin_table tbody tr').each( function () {
		this.insertBefore(  nCloneTd.cloneNode( true ), this.childNodes[0] );
	} );
	
	/*
	 * Initialse DataTables, with no sorting on the 'details' column
	 */
	var oTable = $('#admin_table').dataTable( {
		"aoColumnDefs": [
			{ "bSortable": false, "aTargets": [ 0 ] }
		],
		"aaSorting": [[1, 'asc']]
	});
	
	/* Add event listener for opening and closing details
	 * Note that the indicator for showing which row is open is not controlled by DataTables,
	 * rather it is done here
	 */
	$('#admin_table tbody td img').live('click', function () {
		var nTr = this.parentNode.parentNode;
		if ( this.src.match('details_close') )
		{
			/* This row is already open - close it */
			this.src = "resources/images/details_open.png";
			oTable.fnClose( nTr );
		}
		else
		{
			/* Open this row */
			this.src = "resources/images/details_close.png";
			oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
		}
	} );
} );

function fnGetSelected( oTableLocal )
{
    var aReturn = new Array();
    var aTrs = oTableLocal.fnGetNodes();
     
    for ( var i=0 ; i<aTrs.length ; i++ )
    {
        if ( $(aTrs[i]).hasClass(select) )
        {
            aReturn.push( aTrs[i] );
        }
    }
    return aReturn;
}
</script>
<div style="margin: 2px;">
	<a href="home?list=warnings&sub=registration">Registracie</a>
	<a href="home?list=warnings&sub=rights">Prava</a>
	
	{if isset($data.sub['sub'])}
	{if $data.sub['sub'] eq 'registration'}
	<table id="admin_table" cellpadding="0" cellspacing="0" border="0" class="display">
		  <thead>
          <tr>
            <th>Meno</th>
            <th>Priezvisko</th>
            <th>E-mail</th>
          </tr>
        </thead>
        <tbody>
		{foreach from=$data.applications item=foo}
		<tr>
		    <td>{$foo->name}</td>
		    <td>{$foo->surname}</td>
		    <td>{$foo->email}</td>
    	</tr>
    	{/foreach}
    	</tbody>
	</table>
	{/if}
	
	{if $data.sub['sub'] eq 'rights'}
	<table id="admin_table" cellpadding="0" cellspacing="0" border="0" class="display">
		  <thead>
          <tr>
          	<th> </th>
            <th>Meno</th>
            <th>Priezvisko</th>
            <th>Práva</th>
            <th>Miestnosť</th>
          </tr>
        </thead>
        <tbody>
		{foreach from=$data.all item=foo}
		<tr>
		    
		   
		    	<td>{$foo.apply_id}</td>
		    	<td>{$foo.name}</td>
		    	<td>{$foo.surname}</td>
		    	<td>watch: {$foo.watch} add:{$foo.add} edit:{$foo.edit} delete:{$foo.delete}</td>
		    	<td>{$foo.room_name}</td>
		    
    	</tr>
    	{/foreach}
    	</tbody>
	</table>
	{/if}
	{/if}
</div>